#!/usr/bin/env python
# -*- coding: utf-8 -*-
import torch


def test1():
    x = torch.tensor([1.0, 2, 4, 8])
    y = torch.tensor([2, 2, 2, 2])
    print(x + y)
    print(x - y)
    print(x * y)
    print(x / y)
    print(x ** y)


def test2():
    x = 1
    print('id(x): ', id(x))
    x += 2
    print('id(x): ', id(x))


def test3():
    x = torch.arange(12)
    x = x.reshape(3, 4)
    print(x)

    y = x * x
    print(y)

    z = torch.zeros_like(y)
    print(z)
    print('id(z):', id(z))
    z[:] = x + y
    print(z)
    print('id(z):', id(z))

    print(x)
    before = id(x)
    x += y
    print(x)
    print(id(x) == before)


def test4():
    a = torch.arange(20, dtype=torch.float32).reshape(5, 4)
    x = torch.arange(4, dtype=torch.float32)
    print(a)
    print(a.shape)
    print(x)
    print(x.shape)
    ax = torch.mv(a, x)
    print(ax)

    b = torch.ones(4, 3)
    c = torch.mm(a, b)
    print(c)


def main():
    test4()


if __name__ == '__main__':
    main()
